<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');


$time = $_GET['time'];

$shopTempList = Shop::GetAllShops();
$shopList1 = array();
foreach($shopTempList as $k => $v){
	$shopList1[ $v['id'] ] = $v;
}


$searchDate = $_GET['start_date'];
$getDateArray = array();
if( preg_match("#/#", $searchDate) ){
	$getDateArray = explode("/", $searchDate);
}else if( preg_match("#-#", $searchDate) ){
	$getDateArray = explode("-", $searchDate);
}else{
	array_push($getDateArray, substr($searchDate, 0, 4));
	array_push($getDateArray, substr($searchDate, 4, 2));
	array_push($getDateArray, substr($searchDate, 6, 2));
}

$time['startYear'] = $getDateArray[0];
$time['startMonth'] = $getDateArray[1];
$time['startDay'] = $getDateArray[2];

$searchDate = $_GET['end_date'];
$getDateArray = array();
if( preg_match("#/#", $searchDate) ){
	$getDateArray = explode("/", $searchDate);
}else if( preg_match("#-#", $searchDate) ){
	$getDateArray = explode("-", $searchDate);
}else{
	array_push($getDateArray, substr($searchDate, 0, 4));
	array_push($getDateArray, substr($searchDate, 4, 2));
	array_push($getDateArray, substr($searchDate, 6, 2));
}

$time['endYear'] = $getDateArray[0];
$time['endMonth'] = $getDateArray[1];
$time['endDay'] = $getDateArray[2];


$shopList = Users::GetAll();

$serviceList = Service::GetAll();

$tmp_date=date("Ymd");
$tmp_year=substr($tmp_date,0,4) * 1;
$tmp_mon =substr($tmp_date,4,2) * 1;
$tmp_day = substr($tmp_date, 6, 2) * 1;

$time['startYear'] = $time['startYear'] > 0 ? $time['startYear'] : $tmp_year;
$time['startMonth'] = $time['startMonth'] > 0 ? $time['startMonth'] : $tmp_mon;
$time['startDay'] = $time['startDay'] > 0 ? $time['startDay'] : $tmp_day;
$time['endYear'] = $time['endYear'] > 0 ? $time['endYear'] : $tmp_year;
$time['endMonth'] = $time['endMonth'] > 0 ? $time['endMonth'] : $tmp_mon;
$time['endDay'] = $time['endDay'] > 0 ? $time['endDay'] : $tmp_day;

$preengageShopIdCount = array();
foreach($shopList AS $_k=>$_v) {
	$tempList = array();
	//Logs::setLog("===============================loop  user....".$_v['id']);
	foreach($serviceList as $k1 => $v1){
		//Logs::setLog("===============================loop  service....".$_v['id']."<serviceId>".$v1['id']);
		//Logs::setLog($time['startYear']."||".$time['startMonth']."||".$time['startDay']."||".$time['endYear']."||".$time['endMonth']."||".$time['endDay']);
		$tempTemp = Preengage::GetOrderedCountByUserId($_v['id'], $v1['id'], $time['startYear'], $time['startMonth'], $time['startDay'], $time['endYear'], $time['endMonth'], $time['endDay']);
		/*foreach($tempTemp as $k2 => $v2){
			Logs::setLog(  "  inner tempTemp $k2 => $v2			");
		}*/
		//Logs::setLog(" is tempTemp is null ".$tempTemp."||<>".$tempTemp['count']);
		$tempList[$v1['id']] = $tempTemp;
	}
	$preengageShopIdCount[$_v['id']] = $tempList;
}
    
$yearList = array();
for($tempYear = date('Y'), $index = 0; $index < 3; $index++){
	array_push($yearList, $tempYear - $index);
}

$monthList = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
$dayList = array();
for($index = 1; $index <= 31; $index++){
	array_push($dayList, $index);
}
if( $oauthMap[60] == null){
	exit;
}
include template('/service/vip_list');


//include template('service_staff_index');
//include template('subscribe');
